package com.xz.xzutils.components.console;

import com.intellij.execution.filters.Filter;
import com.intellij.execution.filters.HyperlinkInfo;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.actionSystem.AnAction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 * sql控制台,实现了ConsoleView,方便扩展自定义方法
 *
 * @author DONG.WANG17@HAND-CHINA.COM
 * @since 2025-02-13 10:51
 */
public class SqlConsole implements ConsoleView {
    private final ConsoleView consoleView;

    public SqlConsole(ConsoleView consoleView) {
        this.consoleView = consoleView;
    }

    public ConsoleView getConsoleView() {
        return consoleView;
    }

    @Override
    public void print(@NotNull String text, @NotNull ConsoleViewContentType contentType) {
        consoleView.print(text, contentType);
    }

    @Override
    public void clear() {
        consoleView.clear();
    }

    @Override
    public void scrollTo(int offset) {
        consoleView.scrollTo(offset);
    }

    @Override
    public void attachToProcess(@NotNull ProcessHandler processHandler) {
        consoleView.attachToProcess(processHandler);
    }

    @Override
    public void requestScrollingToEnd() {
        consoleView.requestScrollingToEnd();
    }

    @Override
    public boolean isOutputPaused() {
        return consoleView.isOutputPaused();
    }

    @Override
    public void setOutputPaused(boolean value) {
        consoleView.setOutputPaused(value);
    }

    @Override
    public boolean hasDeferredOutput() {
        return consoleView.hasDeferredOutput();
    }

    @Override
    public void performWhenNoDeferredOutput(@NotNull Runnable runnable) {
        consoleView.performWhenNoDeferredOutput(runnable);
    }

    @Override
    public void setHelpId(@NotNull String helpId) {
        consoleView.setHelpId(helpId);
    }

    @Override
    public void addMessageFilter(@NotNull Filter filter) {
        consoleView.addMessageFilter(filter);
    }

    @Override
    public void printHyperlink(@NotNull String hyperlinkText, @Nullable HyperlinkInfo info) {
        consoleView.printHyperlink(hyperlinkText, info);
    }

    @Override
    public int getContentSize() {
        return consoleView.getContentSize();
    }

    @Override
    public boolean canPause() {
        return consoleView.canPause();
    }

    @Override
    public AnAction @NotNull [] createConsoleActions() {
        return consoleView.createConsoleActions();
    }

    @Override
    public void allowHeavyFilters() {
        consoleView.allowHeavyFilters();
    }

    @Override
    public @NotNull JComponent getComponent() {
        return consoleView.getComponent();
    }

    @Override
    public JComponent getPreferredFocusableComponent() {
        return consoleView.getPreferredFocusableComponent();
    }

    @Override
    public void dispose() {
        consoleView.dispose();
    }


    /**
     * 输出带换行的文本
     *
     * @param text        文本
     * @param contentType 文本类型
     */
    public void println(@NotNull String text, @NotNull ConsoleViewContentType contentType) {
        consoleView.print(text + "\n", contentType);
    }

    public void logInfo(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.LOG_INFO_OUTPUT);
    }

    public void logInfoLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.LOG_INFO_OUTPUT);
    }

    public void logDebug(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.LOG_DEBUG_OUTPUT);
    }

    public void logDebugLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.LOG_DEBUG_OUTPUT);
    }

    public void logWarn(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.LOG_WARNING_OUTPUT);
    }

    public void logWarnLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.LOG_WARNING_OUTPUT);
    }

    public void logError(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.LOG_ERROR_OUTPUT);
    }

    public void logErrorLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.LOG_ERROR_OUTPUT);
    }

    public void logVerbose(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.LOG_VERBOSE_OUTPUT);
    }

    public void logVerboseLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.LOG_VERBOSE_OUTPUT);
    }

    public void normal(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.NORMAL_OUTPUT);
    }

    public void normalLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
    }

    public void error(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.ERROR_OUTPUT);
    }

    public void errorLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.ERROR_OUTPUT);
    }

    public void system(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.SYSTEM_OUTPUT);
    }

    public void systemLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.SYSTEM_OUTPUT);
    }

    public void userInput(@NotNull String text) {
        consoleView.print(text, ConsoleViewContentType.USER_INPUT);
    }

    public void userInputLn(@NotNull String text) {
        consoleView.print(text + "\n", ConsoleViewContentType.USER_INPUT);
    }
}
